package com.itheima.app.controller;

import com.itheima.app.manager.MovementManager;
import com.itheima.domain.mongo.Movement;
import com.itheima.domain.vo.PageBeanVo;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

/**
 * @Author 请不要叫我高司令
 * @Date 2022/3/17 16:17
 * @Version 1.0
 */

@RestController
public class MovementController {

    @Autowired
    private MovementManager movementManager;


    //发布动态
    @PostMapping("/movements")
    public void saveMovement(Movement movement, MultipartFile[] imageContent) throws IOException {

        movementManager.saveMovement(movement, imageContent);

    }

    //查看自己的动态
    @GetMapping("/movements/all")
    public ResponseEntity findMyMovementByPage(
            Long userId,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {

            return movementManager.findMyMovementByPage(userId, pageNum, pageSize);

    }

    //查看好友动态
    @GetMapping("/movements")
    public ResponseEntity findFriendMovementByPage(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {

        return movementManager.findFriendMovementByPage(pageNum, pageSize);

    }

    //查看推荐动态
    @GetMapping("/movements/recommend")
    public ResponseEntity findRecommendMovementByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {

        return movementManager.findRecommendMovementByPage(pageNum, pageSize);


    }


    //点赞
    @GetMapping("/movements/{publishId}/like")
    public ResponseEntity movementLike(@PathVariable String publishId) {

        return movementManager.movementLike(publishId);

    }

    // 取消点赞
    @GetMapping("/movements/{publishId}/dislike")
    public ResponseEntity movementDisLike(@PathVariable String publishId) {
        // 调用manager
        return movementManager.movementDisLike(publishId);
    }

    //喜欢
    @GetMapping("/movements/{publishId}/love")
    public ResponseEntity movementLove(@PathVariable String publishId) {

        return movementManager.movementLove(publishId);

    }

    //取消喜欢
    @GetMapping("/movements/{publishId}/unlove")
    public ResponseEntity movementDisLove(@PathVariable String publishId) {

        return movementManager.movementDisLove(publishId);

    }

    //单条动态详情
    @GetMapping("/movements/{publishId}")
    public ResponseEntity findMovementVoById(@PathVariable String publishId) {

        //调用manager
        return movementManager.findMovementVoById(publishId);

    }


    // 查看评论分页
    @GetMapping("/comments")
    public ResponseEntity findCommentVoByPage(
            @RequestParam("movementId") String publishId,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10")Integer pageSize

            ) {

        return movementManager.findCommentVoByPage(publishId, pageNum, pageSize);


    }


    //发表评论
    @PostMapping("/comments")
    public void movementComment(@RequestBody Map<String, String> map) {

        String publishId = map.get("movementId");
        String content = map.get("comment");

        movementManager.movementComment(publishId, content);
    }


}
